<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="协议标题">
              <a-input placeholder="请输入协议标题" v-model="queryParam.title"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="permissionData.protocolAdd" @click="handleAdd" type="primary" icon="plus">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table ref="table" size="middle" :scroll="{x:true}" rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap" @change="handleTableChange">
        <span slot="action" slot-scope="text, record">
          <span>
            <span>
              <a @click="handleEdits(record)">编辑</a>
              <a-divider type="vertical" />
            </span>
            <span>
              <a @click="handleDeletes(record)">删除</a>
              <a-divider type="vertical" />
            </span>
          </span>
        </span>

      </a-table>
    </div>
    <j-modal title="文章列表" width="50%" :visible="show" @ok="handleOk" @cancel="show=false" cancelText="关闭">
      <j-form-container>
        <div slot="detail">
          <a-form-model>
            <a-row>
              <a-col :span="12">
                <a-form-model-item label="标题" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入标题" v-model="query.title"></a-input>
                </a-form-model-item>
              </a-col>
              <a-col :span="12">
                <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <j-dict-select-tag dict-code="new_kate" v-model="query.kate"></j-dict-select-tag>
                </a-form-model-item>
              </a-col>
              <a-col :span="24">
                <a-form-model-item label="内容" style="min-height: 300px">
                  <j-editor v-model="query.content" :height="500" />
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </div>
      </j-form-container>
    </j-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ProtocolModal from './modules/ProtocolModal'
import { mapGetters } from 'vuex'
import { deleteAction, postAction } from '../../api/manage'

export default {
  name: 'ProtocolList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ProtocolModal
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      description: '文章列表',
      show: false,
      query: {},
      // 表头
      columns: [
        {
          title: '协议类型',
          align: "center",
          dataIndex: 'kate_dictText'
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/NewsBase/mkNewsBase/list",
        add: '/NewsBase/mkNewsBase/add',
        delete: "/protocol"
      },
    }
  },
  created() {
  },
  computed: {
    ...mapGetters(["permissionData"]),
  },
  methods: {
    handleOk() {
      let url1 = '/NewsBase/mkNewsBase/add'
      let url2 = '/NewsBase/mkNewsBase/edit'
      let url = ''
      if (this.query.id) {
        url = url2
      } else {
        url = url1
      }
      postAction(url, this.query).then(res => {
        console.log(res)
        if (res.success) {
          this.show = false
          this.$message.success('操作成功')
          this.searchQuery()
        }
      })
    },
    handleEdits(e) {
      this.show = true
      this.query = e
    },
    handleDeletes(e) {
      console.log(e)
      deleteAction('/NewsBase/mkNewsBase/delete', { id: e.id }).then(res => {
        console.log(res)
        if (res.success) {
          this.$message.success('操作成功')
          this.searchQuery()
        }
      })
    },
    handleAdd() {
      this.query = {}
      this.show = true
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>